
	
	
	export default {
		data() {
			return {
				notifications : [],
				topic_id : '',
				like_id : '',
				readindex : '',
				type: ''
			}
		},
		onLoad:function(){
			let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
			let curRoute = routes[routes.length - 1].route // 获取当前页面路由，也就是最后一个打开的页面路由
			if( curRoute == "pages/message/likes") {
				this.type = "TopicLiked"
			}
			if( curRoute == "pages/message/collections") {
				this.type = "TopicCollected"
			}
			if( curRoute == "pages/message/replies") {
				this.type = "TopicReplied"
			}
			console.log(this.type);
			this.getNotification();
		},
		methods: {
			getNotification() {
				uni.showLoading({
					title:"加载中...."
				})
				uni.request({
				url:uni.getStorageSync('domain') + '/api/v1/user/notifications/' + this.type,					
					method: 'GET',
					header: {
						'Accept': 'application/json',
						'Authorization' : 'Bearer ' + uni.getStorageSync('access_member_info').access_token
					},
					success: res => {
						if(res.statusCode == 401) {
							uni.redirectTo({
								url:'/pages/member/member'
							})
						} else {						
							if(res.data.notifications.total == 0) {
								this.empty = true
							} else {
								this.notifications = res.data.notifications.data
							}
						}						
						console.log('loadIndexNew', this.notifications);
						uni.hideLoading();
					},
					fail: () => {},
					complete: () => {}
				});
			},
			readMessage(e) {
				this.like_id = e.currentTarget.dataset.likeid;
				this.topic_id = e.currentTarget.dataset.topicid;
				this.readindex = e.currentTarget.dataset.readindex
				uni.showLoading({
					title:"加载中...."
				})
				uni.request({
				url:uni.getStorageSync('domain') + '/api/v1/user/read/notifications/' + this.like_id,					
					method: 'post',
					header: {
						'Accept': 'application/json',
						'Authorization' : 'Bearer ' + uni.getStorageSync('access_member_info').access_token
					},
					success: res => {
						if(res.statusCode == 401) {
							uni.redirectTo({
								url:'/pages/member/member'
							})
						} else {						
							if(res.data.status == 'success') {
								this.notifications[this.readindex].read_at = "now"
								this.$refs.bottom.subCount()
								this.testingExist()
							}
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			testingExist(e) {
				if(e) {
					this.topic_id = e.currentTarget.dataset.topicid;
				}			
				uni.request({
				url:uni.getStorageSync('domain') + '/api/v1/topicsexist/' + this.topic_id,					
					method: 'GET',
					header: {
						'Accept': 'application/json',
						'Authorization' : 'Bearer ' + uni.getStorageSync('access_member_info').access_token
					},
					success: res => {
						if(res.data.result == "success") {
							setTimeout(() => {
								uni.navigateTo({
									url:"/pages/article/article?TopicId=" + this.topic_id,
								})
							},700)
						}
						if(res.data.result == "fail") {
							uni.showToast({
								title:'瞬间已删除',
								icon:'error'
							})
						}
						uni.hideLoading()
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}